from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from goods.models import SPU
from meiduo_admin.serializers.options import OptionsSerializer

from goods.models import SpecificationOption
from meiduo_admin.serializers.options import SPUSerializer
from meiduo_mall.apps.meiduo_admin.utils import PageNum


class OptionsView(ModelViewSet):
    # 指定查询集
    queryset = SpecificationOption.objects.all()
    # 指定序列化器
    serializer_class = OptionsSerializer
    # 指定分页器
    pagination_class = PageNum
    # 指定权限
    permission_classes = [IsAdminUser]

    def simple(self, request):
        SKU = SPU.objects.all()
        ser = SPUSerializer(SKU, many=True)
        return Response(ser.data)